package com.beerandjesus.calc.parse;

import java.util.List;
import java.util.ArrayList;
import java.util.Calendar;
import java.text.SimpleDateFormat;

/**
 * Date: Feb 22, 2008
 * Time: 12:49:47 PM
 */
public class TracksAndTimes {
    List<TrackAndTime> tracks = new ArrayList<TrackAndTime>();
    private Calendar cal = Calendar.getInstance();
    private SimpleDateFormat fmt = new SimpleDateFormat("H'h' m:ss");
    private boolean debug = false;

    public void add(TrackAndTime track) {
        tracks.add(track);
    }

    public String getHTMLTrackList() {
        StringBuffer sb = new StringBuffer();
        for (TrackAndTime track : tracks) {
            sb.append(track.getTrack()).append("<br />\n");
            if (debug) {
                sb.append("<!--\n").append(track.getTotalBreakdown()).append("\n-->\n");
            }
        }
        return sb.toString();
    }

    public String getHTMLTimeList() {
        StringBuffer sb = new StringBuffer();
        cal.clear();
        cal.set(Calendar.HOUR, 0);
        for (TrackAndTime track : tracks) {
            cal.add(Calendar.MINUTE, track.getTime().get(Calendar.MINUTE));
            cal.add(Calendar.SECOND, track.getTime().get(Calendar.SECOND));
            sb.append(fmt.format(cal.getTime())).append("<br />\n");
        }
        return sb.toString();
    }

    public void setDebug(boolean debug) {
        this.debug = debug;
    }

    public List<TrackAndTime> getTracks() {
        return tracks;
    }
}
